<template>
    <div id=push>
        <div>
            <!-- 查询 -->
            <el-form :inline="true" ref="form" :model="form" :rules="rules" class="demo-form-inline">
                <!-- 查询 -->
                <el-form-item label="">
                    <el-input v-model="form.loginName" placeholder="登录名"></el-input>
                    <el-input v-model="form.loginPwd" type="password" placeholder="密码"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit('form')">查询</el-button>
                </el-form-item>
            </el-form>
        </div>

    </div>
  </template>

 <script>
    export default {
      data() {
        return {
            form:{
                loginName: '',
                loginPwd:''
            },
            rules:{
                loginName: [{
                    required: true,
                    message: '请输入登录名',
                    trigger: 'blur'
                }],
                loginPwd:[{
                    required: true,
                    message: '请输入密码',
                    trigger: 'blur'
                }]
            }
            
        }
      },
        
        methods: {
            //添加
            onSubmit(form){
                console.log(this.form);
                this.$refs[form].validate((valid) => {
                    if(valid){
                        this.axios({
                        url: 'https://localhost:44324/api/Users/Login',
                        method: 'post',
                        data: this.form
                        }).then((res) => {
                            if (res.data.code > 0) {
                                console.log();
                                this.$message({
                                    type: 'success',
                                    message: '登录成功!'
                                });
                                this.$router.push("/Product");
                            } else {
                                this.$message({
                                type: 'info',
                                message: '已取消登录'
                                })
                            }
                        })
                    }else{
                        console.log('error submit!');
                        return false;
                    }
                })
                
            }
            
        }
    }
  </script>
